<template>
<!-- 上传厂家证照的modal -->
  <div>
    <basic-modal :modalOpt="modal" :footer="null" @closeModal="closeModal">
      <template>
        <search-layout
          :formInfos="q_formInfos"
          :formDatas="q_formDatas"
          message=""
          @onFind="onFind"
        ></search-layout>
        <div style="clear:both;height:20px"></div>
        <batch-operat-btn 
          :optData="optText" @onOptData="onBatchAudit"
        >
        </batch-operat-btn>
        <a-list-table
          :columns="columns"
          :tableData="listdata"
          :pagination="pagination"
          :isSelecttion="true"
          :loading="loading"
          @onTableChange="handleTableChange"
          @onselectChange="onselectChange"
        >
        </a-list-table>
      </template>
      
    </basic-modal>
  </div>
</template>

<script>
import basicModal from '../common/basicModal'
import searchLayout from '@/views/app/biz/common/searchLayout'
import batchOperatBtn from '@/views/app/biz/common/batchOperatBtn'
import tableLayout from '@/views/app/biz/common/index'
import aListTable from '@/views/app/biz/common/aListTable'
import {
  getByConditions,
  getByConditionsCount,
  auditInfo
} from '@/views/app/biz/purchasedGoods/purchasedgoods'

const columns = [
  //   { title: '数据有效区域(国、省、市、县、院)', dataIndex: 'areaUse', key: 'areaUse', align: 'center' },
  // { title: '商品自编码', dataIndex: 'code', key: 'code', align: 'center' },
  { title: '标准编码', dataIndex: 'standardCode', key: 'standardCode', align: 'center' },
  { title: '品名', dataIndex: 'productNameZh', key: 'productNameZh', align: 'center',scopedSlots: { customRender: 'productNameZh' } },
//   { title: '英文名称', dataIndex: 'productNameEn', key: 'productNameEn', align: 'center' },
  { title: '通用名', dataIndex: 'commonName', key: 'commonName', align: 'center' },
  { title: '供应商名称', dataIndex: 'supplierOrgName', key: 'supplierOrgName', align: 'center',scopedSlots: { customRender: 'supplierOrgName' } },
  // { title: '一级分类', dataIndex: 'first', key: 'first', align: 'center' },
  // { title: '二级分类', dataIndex: 'second', key: 'second', align: 'center' },
  // { title: '三级分类', dataIndex: 'third', key: 'third', align: 'center' },
//   { title: '规格（特征、参数）', dataIndex: 'spec', key: 'spec', align: 'center' },
//   { title: '型号(剂型)', dataIndex: 'model', key: 'model', align: 'center' },
//   { title: '医保代码', dataIndex: 'medicareCode',key: 'medicareCode',   align:'center', },
//   { title: '描述', dataIndex: 'disc', key: 'disc', align: 'center' },
  { title: '品牌', dataIndex: 'brand', key: 'brand', align:'center' },
//   { title: '上市许可持有企业社会编码', dataIndex: 'mahCode', key: 'mahCode', align: 'center' },
//   { title: '上市许可持有企业中文名', dataIndex: 'mahZh', key: 'mahZh',align:'center'  },
//   { title: '上市许可持有企业英文名', dataIndex: 'mahEn', key: 'mahEn', align: 'center' },
//   { title: '生产企业社会编码', dataIndex: 'manufacturerCode', key: 'manufacturerCode', align: 'center' },
  { title: '生产企业名称', dataIndex: 'manufacturerZh', key: 'manufacturerZh',align:'center', scopedSlots: { customRender: 'manufacturerZh' } },
//   { title: '生产企业英文名称', dataIndex: 'manufacturerEn', key: 'manufacturerEn', align: 'center' },
  { title: '产地', dataIndex: 'origin', key: 'origin', align: 'center' },
//   { title: '产品类别(字典medicalCategory)', dataIndex: 'category', key: 'category', align: 'center' },
//   { title: '计量单位', dataIndex: 'measurement', key: 'measurement', align: 'center' },
//   { title: '药品本位码', dataIndex: 'sdc', key: 'sdc', align: 'center' },
//   { title: '当前批准类型(字典medicalApprovalType)', dataIndex: 'approvalType', key: 'approvalType', align: 'center' },
  { title: '注册证号', dataIndex: 'approvalNum', key: 'approvalNum', align: 'center',scopedSlots: { customRender: 'approvalNumlink' }},
  // { title: '厂家证照', dataIndex: 'manufacturerLicense',width: 65, key: 'manufacturerLicense', align: 'center',scopedSlots: { customRender: 'manufacturerLicense' } },
  // { title: '授权书', dataIndex: 'letterAuthorization', width: 65,key: 'letterAuthorization', align: 'center',scopedSlots: { customRender: 'letterAuthorization' } },
//   { title: '当前有效期始', dataIndex: 'approvalDate', key: 'approvalDate', align: 'center' },
  { title: '有效期止', dataIndex: 'validDate', key: 'validDate', align: 'center' },
  { title: '状态', dataIndex: 'state', key: 'state', align: 'center',scopedSlots: { customRender: 'saleGoodsState' } },
  { title: '结算方式', dataIndex: 'settlement', key: 'settlement', align: 'center' }, 
]

export default {
  components: {
    basicModal,
    searchLayout,
    batchOperatBtn,
    tableLayout,
    aListTable
    
  },
  data() {
    return {
      loading: false,
      modal: {
        modalVisible: false,
        modalTitle: '选择商品',
        modalWidth: '80vw',
        maxHeight:'70vh'
      },
      pagination: {
        //分页配置
        current: 1, //当前页码 current
        pageSize: 10, //每页显示条数 pageSize
        total: 1,
        showQuickJumper: true,
        showSizeChanger: true,
        pageSizeOptions: ['2', '10', '50', '100'],
      },
      // 查询表单
      q_formInfos: [
        { label: '品名', name: 'productNameZh', type: 'input', placeholder: '品名' },
        { label: '注册证号',name: 'approvalPid',type: 'zchselect', zhuangTai:'全部',placeholder: '注册证号'},
        { label: '供应商', name: 'supplierOrgPid', type: 'supplier',isDisabled:true, placeholder: '供应商' },
        { label: ['查询', '重置'], type: 'botton' }
      ],
      // 查询表单绑定数据
      q_formDatas: {
        productNameZh: null,
        approvalPid: null,
        supplierOrgPid: null,
        state:null
      },
      columns: columns,
      listdata: [],
      optText: '批量添加',
      selectedRowKeys: [],
      selectedRows: [],
    }
  },
  computed: {},
  mounted() {
    
  },
  methods: {
    // 点击了添加
    addModal(val) {
      console.log(this.appState.saleGoodsState.audited);
      this.modal.modalVisible = true
      this.modal.modalTitle = '选择商品'
      this.q_formDatas.state=this.appState.saleGoodsState.audited.code
      this.q_formDatas.supplierOrgPid=val
      this.getTotal()
      this.getList(this.q_formDatas)
    },
    // 关闭模态详细框
    closeModal() {
      // this.modal.modalVisible = false
      // this.selectedRowKeys = []
      // this.selectedRows = []
      
      Object.assign(this.$data,this.$options.data())
      this.$emit('close')
    },
    // 添加到表格
    onSubmit(form){
      console.log(form);
      this.$emit('onAddInfo',form)
    },
    // 初始化页面时得到总数
    async getTotal() {
      let pages = ''
      pages = await getByConditionsCount(this.q_formDatas)
      console.log(pages)
      if (pages && pages.code && pages.code === 'C1') {
        const pagination = { ...this.pagination }
        pagination.total = pages.data
        this.pagination = pagination
        this.pagination.showTotal =  (showTotal) => {return `共 ${showTotal} 条`}
      }
    },
    // 初始化查询时的数据列表
    async getList(params) {
      console.log('请求列表时传入的数据', params)
      this.loading = true
      let listdata = []
      let res = ''
      res = await getByConditions(params, this.pagination)
      this.loading = false
      console.log(res)
      if (res && res.code && res.code === 'C1' && res.data) {
        const resdata = res.data
         for (let item of resdata) {
            listdata.push({
               key: item.pid,
               ...item
               }
            )
         }
         this.listdata =listdata
      } else {
        this.listdata = []
      }
    },
    // 触发改变页码,筛选,排序时的回调
    handleTableChange(pagination, filters, sorter) {
      this.pagination.current = pagination.current
      this.pagination.pageSize = pagination.pageSize
      this.getList(this.q_formDatas)
    },
    // 查询按钮
    onFind (){
      this.pagination.current = 1
      this.getTotal()
      this.getList(this.q_formDatas)
    },

    // 多选批量操作
    onselectChange(selectedRowKeys, selectedRows) {
      this.selectedRowKeys = selectedRowKeys
      this.selectedRows = selectedRows
    },
    onBatchAudit() {
      if (this.selectedRows.length) {
        this.$emit('onAddInfo',this.selectedRows)
      } else {
        this.$message.warning({ content: '未选择要添加的商品', duration: 3 })
      }
    }
  },
}
</script>

<style>
.recordBox{
  width: 100%;
  min-height: 80px;
}
</style>